/*
 * main.c
 *
 *  Created on: 2011-8-25
 *      Author: jfhu
 */

#include "leftistheap.h"

void test1(void)
{
	heap h1, h2;
	item i1,i2,i3,i4;
	item j1,j2,j3,j4;
	pHeap h;

	i1.rank = 1;
	i1.value = 6;

	i2.rank = 2;
	i2.value = 10;

	i3.rank = 1;
	i3.value = 11;

	i4.rank = 1;
	i4.value = 20;

	i1.leftChild = &i2;
	i1.rightChild = NULL;

	i2.leftChild = &i3;
	i2.rightChild = &i4;

	i3.leftChild = i3.rightChild = NULL;

	i4.leftChild = i4.rightChild = NULL;

	j1.rank = 2;
	j1.value = 5;

	j2.rank = 1;
	j2.value = 15;

	j3.rank = 1;
	j3.value = 8;

	j4.rank = 1;
	j4.value = 30;

	j1.leftChild = &j2;
	j1.rightChild = &j3;

	j2.leftChild = &j4;
	j2.rightChild = NULL;

	j3.leftChild = j3.rightChild = NULL;

	j4.leftChild = j4.rightChild = NULL;

	h1.root = &i1;
	h2.root = &j1;

	h = meld(&h1, &h2);

	printfHeap(h);

}

int main()
{
	int arr[10] = {1,2,3,4,5,6,7,8,9,10};
	item pit[10];
	int i;
	heap hep;
	pItem minimumItem;
	list l;

	/* Test makeheap function */
	pHeap h = makeheap(arr, 10);
	printf("Function makeheap test\n");
	printfHeap(h);

	/* Test insert function */
	printf("Insert function test\n");
	initializeheap(&hep);
	for (i = 0; i < 10; i++) {
		pit[i].value = arr[i];
		initializeitem(pit + i);
		insert(pit + i, &hep);
	}
	printfHeap(&hep);

	printf("Deletemin function test\n");
	printf("Heap before deletion\n");
	printfHeap(&hep);

	/* Test deletemin function */
	minimumItem = deletemin(&hep);
	printf("The minimum value of heap is:%d(%d, %d)\n", minimumItem->value, minimumItem->leftChild->value, minimumItem->rightChild->value);
	printf("Heap after deletion\n");
	printfHeap(&hep);

	/* Test the listmin function */
	initializelist(&l);
	listmin(&l, 5, hep.root);
	printf("Test listmin function\n");
	printfList(&l);

	return 0;
}


